

console.log("sheindetail ajax")
/*setTimeout(() => {
    const firstAddButton = $('.product-card__add-btn').first();
    console.log(firstAddButton.html())
    // 使用 trigger() 方法触发 click 事件
    firstAddButton.trigger('click');
},2000);*/

var headers = {};
chrome.runtime.onMessage.addListener(async (msg, sender) => {

    console.log(msg)
    getDataByApiStaticRealTime(msg);


    /*console.log(msg);
    if(msg.type && msg.type=='LOG_REQUEST'){
        headers = msg.headers;
        return;
    }
    const button = document.getElementById('myButton');

    var url = "/api/productInfo/quickView/get?_ver=1.1.8&_lang=zh-tw&goods_id="+msg.data.goods_id+"&mallCode=1&lockmall=0&isQuick=1&bid="+msg.data.id;
   /!* console.log(headers);

    const headers_fetch = new Headers();
    headers.forEach(header => {
        headers_fetch.append(header.name, header.value);
    });*!/

    fetch(url, {
        method: 'GET',
       // headers: headers_fetch,
        credentials: 'include' // 如果需要携带 cookie
    })
        .then(response => {
            if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
            return response.json();
        })
        .then(data => {
            if(data.code=='836100'){
                console.log(data);

                console.log("shein block");
                var type = "sheinblock";
                if(location.href.includes("s1.shein.com")){
                    type = "sheinblock_yn";
                }
                chrome.runtime.sendMessage({ data: {type }, close: false });
                setTimeout(() => {
                    location.reload()
                },100000);
            }else if(data.code=='1405'){
                console.log(data);
                var type = "sheindetaildel";
                var data={}
                data.id = msg.data.id;
                console.log(data);
                chrome.runtime.sendMessage({ data: {type,data }, close: false })

            }else{
                getDataDetailApi(data,msg.data.id,msg.data.goods_id);
            }

        })
        .catch(error => {
            console.log("shein block");
            var type = "sheinblock";
            if(location.href.includes("s1.shein.com")){
                type = "sheinblock_yn";
            }
            chrome.runtime.sendMessage({ data: {type }, close: false });
            setTimeout(() => {
                location.reload()
            },100000);
        });*/

});



function getDataByApiStaticRealTime(msg){
    console.log("start api 3");
    var url = "https://www.shein.com.hk/bff-api/product/get_goods_detail_static_data_v2?_ver=1.1.8&_lang=en&goods_id="+msg.data.goods_id+"&mall_code=1&isUserSelectedMallCode=0&isHideEstimatePriceInfo=0&specialSceneType=0";
    fetch(url, {
        method: 'GET',
        headers: {
            'accept': 'application/json, text/plain, */*',
            'accept-language': 'zh-CN,zh;q=0.9',
            'anti-in': '0_1.9.1_c38d61_-qx5b0yIhYmNyQg4_nzJw02_XsG7Wbct9SKxL8BesDsAtw5l6XjE4uY2weB9dAatfxMSTdlKbd01lOIVfhNNpdD137c835Lx4N4DCfMSfp66DcYAsPXeyIXkj6hz0reu9PPJ-i9Ry-ZcN2QH_fSWLo5hd5uQECpV0q-zBPYRkrx2LUddIH1SEyjz9DNwu173w-XOcJ0sVk_ubuqPT4t3HK7g-8SiJodsQcItiljQVsOCayA9OoYE14OarnEA2HZXsIqKvxi7aidKvdwY7KteHbcLfxjF2_GwfxFfTY9csb6o0b6HX9MvXvcP05Ho2pepxfZ3XTeqw4PYkyHkKqVDxqBwg1xSJKlEOKyXD3SkCaGcVNrmEfP8_6VioIYou7MCZ0TcH6iVDiN5q2AbhJ1XshURP7yOqnZLmjdf8G2l_XfOQ3SHgIIQlG9JFYKoNkZ2MjKdquUeEpPjJ5pR_aH1QrYgeHv9z3AWK2jbjQ4bsfbO0uM_4ZK_iI_qGhaC_QRrOa9RCu_aG2ilaoiDocXnrKv5jUamfWt-IySkyjAikHFo0rybUKZehMiIhoRoTWfeJSE62J0vRjR76_TgrG1XerIZyAG6HNa-Ny1wi_3ZRqsA4RrM5WWmYIrH_MfsI2q1waNo1JJZO9EiXgKFd3kCQJseDQFFf-7CR8uJDYYd7C9i0iGwk8gOyXmswakoO2qKQD_ZaLia0mfiHOd4kXSAfJqNNyqG_vTjeSEXNmZRwN4cGoln1A8FkBEKsMUc6uY7m',
            'armortoken': 'T0_3.3.0_HrzEkoY1JjaE3mp_fOTINtzBb-h-EkHI0vvSoOmZuZcgwjbqAfmTkQm-fjEVe-gXeN9a2jl02nli0HXVAdgRVvXqDIfiPnUWKtA5HvEwH3RAxPc4sBDMcXOJpkm0tW_mqFiuAGw6zghfuIDcFn_Vuyd5REj4JUH6F8gsPL3qzJjakISTWpoJfszsJHKxxwy7_1747379001280',
            'priority': 'u=1, i',
            'referer': 'https://s1.shein.com/',
            'sec-ch-ua': '"Google Chrome";v="135", "Not-A.Brand";v="8", "Chromium";v="135"',
            'sec-ch-ua-mobile': '?0',
            'sec-ch-ua-platform': '"macOS"',
            'sec-fetch-dest': 'empty',
            'sec-fetch-mode': 'cors',
            'sec-fetch-site': 'same-origin',
            'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36',
            // Add other needed headers from the second request here as necessary
        },
        credentials: 'include' // 如果需要携带 cookie
    })
        .then(response => {
            if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
            return response.json();
        })
        .then(data => {
            console.log(data);

            if(data['code']=="200301"){
                var type = "sheindetaildel";
                var data={}
                data.id = msg.data.id;
                console.log(data);
                chrome.runtime.sendMessage({ data: {type,data }, close: false })
                setTimeout(function() {
                    window.close();
                }, 10000);
            }else{
                getDataDetailApiStatic(data,msg.data.id,msg.data.goods_id);
            }


        })
        .catch(error => {
            console.log("api error:");
        });
}







